﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Game
{
    class CharacterControlPlayer : CharacterControl, CommonAction.IActionListener
    {
        private IDK.Camera mCamera;

        private CharacterAction.ActionGroup Actions = new CharacterAction.ActionGroup();

        private CharacterAction.Moving MoveAction;

        public CharacterControlPlayer(IDK.Camera camera)
        {
            mCamera = camera;

            Actions.Add(MoveAction = new CharacterAction.Moving());
        }

        public void OnActivateAction(CommonAction.Action action)
        {
            //for a test
            //Character.LookAtPoint(true, new IDK.Vector3(0, 0, 0));

            if (action is GameAction.PlayerMoveAction)
            {
                GameAction.PlayerMoveAction plAct = (action as GameAction.PlayerMoveAction);
                switch (plAct.States)
                {
                    case GameAction.PlayerMoveAction.State.Forward:
                        MoveAction.Move(true, CharacterAction.Moving.State.Forward);
                        break;
                    case GameAction.PlayerMoveAction.State.TurnLeft:
                        MoveAction.Move(true, CharacterAction.Moving.State.TurnLeft);
                        break;
                    case GameAction.PlayerMoveAction.State.TurnRight:
                        MoveAction.Move(true, CharacterAction.Moving.State.TurnRight);
                        break;
                    case GameAction.PlayerMoveAction.State.Backward:
                        MoveAction.Move(true, CharacterAction.Moving.State.Backward);
                        break;
                    case GameAction.PlayerMoveAction.State.Jump:
                        MoveAction.Move(true, CharacterAction.Moving.State.Jump); // once effect
                        break;
                    case GameAction.PlayerMoveAction.State.Boost:
                        MoveAction.Move(true, CharacterAction.Moving.State.Sprint);
                        break;
                }
            }
        }

        public void OnDeactivateAction(CommonAction.Action action)
        {
            if (action is GameAction.PlayerMoveAction)
            {
                GameAction.PlayerMoveAction plAct = (action as GameAction.PlayerMoveAction);
                switch (plAct.States)
                {
                    case GameAction.PlayerMoveAction.State.Forward:
                        MoveAction.Move(false, CharacterAction.Moving.State.Forward);
                        break;
                    case GameAction.PlayerMoveAction.State.Backward:
                        MoveAction.Move(false, CharacterAction.Moving.State.Backward);
                        break;
                    case GameAction.PlayerMoveAction.State.Boost:
                        MoveAction.Move(false, CharacterAction.Moving.State.Sprint);
                        break;
                    case GameAction.PlayerMoveAction.State.TurnLeft:
                        MoveAction.Move(false, CharacterAction.Moving.State.TurnLeft);
                        break;
                    case GameAction.PlayerMoveAction.State.TurnRight:
                        MoveAction.Move(false, CharacterAction.Moving.State.TurnRight);
                        break;
                }
            }
        }

        public override void Update(Events.ProcessUpdate evnt)
        {
            Character.Actions = Actions;
            IDK.Vector3 pos = Character.Body.GetPosition();
            //pos.y = 6.0f;
            mCamera.LookAt(pos);
            Character.OnUpdate(evnt);
        }
    }
}
